package com.myzl.web.controller.visualization;

import com.myzl.coal.domain.Device;
import com.myzl.coal.domain.Rfid;
import com.myzl.coal.service.IDeviceService;
import com.myzl.coal.service.IRfidService;
import com.myzl.common.core.domain.AjaxResult;
import com.myzl.common.enums.DeviceStatusEnum;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * @ClassName VisualizationControl
 * @Author wzb
 * @Date 2023/6/7 15:02
 * @Description
 */
@RestController
@Slf4j
@Data
@RequestMapping("/visualization/sieve/")
public class SievePlateController {
    private final IRfidService rfidService;
    private final IDeviceService deviceService;

    @GetMapping("/info")
    public AjaxResult info() {
        Rfid rfid = new Rfid();
        List<Rfid> rfids = rfidService.selectInfo(rfid);
        return AjaxResult.success(rfids);
    }

    @GetMapping("/startFlag")
    public AjaxResult startFlag(@RequestParam(defaultValue = "104") Integer deviceId) {
        Device device = deviceService.selectDeviceById(deviceId);
        if (!Objects.isNull(device) && DeviceStatusEnum.ONLINE.getCode().equals(device.getDeviceStatus())){
            return AjaxResult.success(true);
        }
        return AjaxResult.success(false);
    }
    /**
     * 获取筛板设备表详细信息
     */
    @GetMapping(value = "/getSieveDeviceInfo")
    public AjaxResult getSieveDeviceInfo(@RequestParam(defaultValue = "104") Integer deviceId)
    {
        Device device = deviceService.selectDeviceById(deviceId);
        return AjaxResult.success(device);
    }
    @PutMapping("/setSieveConfig")
    public AjaxResult setSieveConfig(@RequestBody Device device) {
        deviceService.replaceConfig(device);
        deviceService.updateById(device);
        return AjaxResult.success();
    }
}
